$(function() {
	//alert("hi");
  
  ///替换原有组合music
    $("#li").hide();
  var bag=JSON.parse(localStorage.getItem('bag'));
  

  //test_getlist_bag(bag);
  //test_bag()
	




  function test_shuffle_bag(e){
          $("#li").hide();
         var bag=JSON.parse(localStorage.getItem('bag'));
         for (i=0;i<bag.length;i++){
          var selector ="#li"+i.toString()
          $(selector).remove();
         }

        // console.log(JSON.stringify(bag));
         shuffle(bag);
         localStorage.setItem('bag',JSON.stringify(bag));
        // combine_Music();
        test_getlist_bag(bag);
         test_bag()



    };
    $('#shuffle').bind('click',test_shuffle_bag );







/**
 * Shuffles array in place.
 * @param {Array} a items An array containing the items.
 */



function test_getlist_bag(bag){
  //combine_Music();
var word_list=[];
var word_def_list=[]

//for (i =0; i<bag.length; i++) {
  bag.forEach(function(item){
 // console.log(i);
  //var item=bag[i];

   var path ="learnmode/jq/"+item.toString();
    
    
       fetch(path)       
        .then(function(response) {
          return response.json();
        })
        .then(function (myJson){
             // $('#'+id_curr+' '+'#user_level').text(item.toString())
            //  var word=myJson.word;
            //console.log(myJson.word);
             // $('#'+id_curr+' '+'#word').text(myJson.word);
             word_list=word_list.concat(myJson.word);
             word_def_list=word_def_list.concat(myJson.word_def);
             localStorage.setItem('word_list',JSON.stringify(word_list))
            localStorage.setItem('word_def_list',JSON.stringify(word_def_list))
             // $('#'+id_curr+' '+'#word_def').text(myJson.word_def); 
      } );
 
});//end foreach


};//end display bag

function test_bag() {


    var word_list=JSON.parse(localStorage.getItem('word_list'))
    var word_list=shuffle(word_list)
    var word_def_list=JSON.parse(localStorage.getItem('word_def_list'))
    var word_def_list=shuffle(word_def_list)

for (i =0; i<word_list.length; i++) {

var id_curr= 'li'+ i.toString();
    $("#li").clone().attr('id',id_curr).show().appendTo("ul")
    $('#'+id_curr+' '+'#word').text(word_list[i]);
    $('#'+id_curr+' '+'#word_def').text(word_def_list[i]);

}
};//end test_bag





});//end main function



